<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

	<div class="modal fade" id="modalUpdate" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Đóng</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">Sửa thông tin thuốc</h4>
				</div>
			<form action="update" id="updateForm">
				<input type="hidden" id="medicineIdUpdate" name="id">
				<div class="modal-body">
					<div class="mb10 input-group">
						<span class="input-group-addon">Tên thuốc &nbsp; &nbsp;
							&nbsp; &nbsp; &nbsp; &nbsp;</span> <input type="text"
							class="form-control" placeholder="Name" name="updateMedicineName" id="updateMedicineName"
							required>
					</div>
					<div class="mb10 input-group">
						<span class="input-group-addon">Chỉ định &nbsp; &nbsp;&nbsp; &nbsp;
							&nbsp; &nbsp; &nbsp; &nbsp;</span> <input type="text"
							class="form-control" placeholder="Chỉ định" name="updateSpecialize" id="updateSpecialize">
					</div>
					<div class="mb10 input-group">
						<span class="input-group-addon">Chống chỉ định &nbsp; &nbsp;
							</span> <input type="text"
							class="form-control" placeholder="Chống chỉ định" name="updateContraindicated" id="updateContraindicated">
					</div>
					<div class="mb10 input-group">
						<span class="input-group-addon">Nhà sản xuất
							&nbsp; &nbsp; &nbsp; &nbsp;</span> <input type="text"
							class="form-control" placeholder="Description" name="updateDescription" id="updateDescription">
					</div>
					<div class="mb10 input-group" id="updateMedicinePrice">
						<span class="input-group-addon">Giá &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
							&nbsp; &nbsp; &nbsp;</span> <input type="text" class="form-control" id="updatePrice"
							placeholder="Price" name="updatePrice">
					</div>
					<div class="mb10 input-group" id="updateMedicineQuantity">
						<span class="input-group-addon">Số lượng &nbsp; &nbsp;&nbsp;
							&nbsp; &nbsp; &nbsp; &nbsp;</span> <input type="text"
							class="form-control" placeholder="Quantity" name="updateQuantity" id="updateQuantity">
					</div>
					<div class="mb10 input-group" id="medicineCategory">
						<span class="input-group-addon">Loại &nbsp; &nbsp; &nbsp;&nbsp;
							&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span> <select
							class="form-control" name='updateCategoryId' id='updateCategoryId'>
							<c:forEach var="category" items="${categories}">
								<option value="${category.getId()}">${category.getName()}</option>
							</c:forEach>
						</select>
					</div>
					<div class="input-group">
						<span class="input-group-addon">Thành phần &nbsp; &nbsp;&nbsp;
							&nbsp;</span>
						<div>
							<input type="text" list="gradientItem" id="updateGradientCheckbox" name="updateGradientCheckbox"
								style="width: 100px;">
							<datalist id="gradientItem">
								<c:forEach var="gradient" items="${gradients}">
									<option value="${gradient.getId()}">${gradient.getName()}</option>
								</c:forEach>
							</datalist>
							<button type="button" class="btn btn-default" id="updatetp" onclick="updateGradientAdd()">Thêm</button>
						</div>
					</div>
					<div class="mb10 input-group">
						<input type="text" id="txtUpdateIngradient" style="width: 300px;" name="updateGradientList" value="">
					</div>
				</div>
				</form>
				<form action="delete" id="deleteMedicine">
					<input type="hidden" name="id" id="deleteMedicineId" value= ""/>
				</form>
					<div class="modal-footer">
						<button type="button" onclick="saveMedicine()" class="btn btn-primary">Lưu</button>
						<button type="button" onclick="deleteMedicine()" class="btn btn-danger btn-square">Xóa</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">Đóng</button>
					</div>
				
<!-- 				<button type="button" onclick="deleteMedicine()" class="btn btn-danger btn-square">Xóa</button> -->
			</div>
		</div>
	</div>
	
	<script>
		function updateGradientAdd(){
			var inputIngradient = document.getElementById("updateGradientCheckbox").value;
			var listIngradient = document.getElementById("txtUpdateIngradient").value;
			document.getElementById("txtUpdateIngradient").value = listIngradient + "," + inputIngradient;
		}
		function saveMedicine(){
			document.getElementById("updateForm").submit();
		}
		function deleteMedicine(){
			debugger;
		    var id = document.getElementById("deleteMedicineId").value;
		    //alert(id);
		    document.getElementById("deleteMedicine").submit();
		    $.ajax({
		        cache: false,
		        type: "GET",
		        url: "delete",
		        data: {
		            "id": id
		        },
		        success: function (data) {
		        	alert("delete completed!");
		        	document.getElementById("deleteMedicineId").submit();
		        },
		        error: function (data) {
		            alert("error");
		        }
		    });
		}
	</script>

